package com.heima.behavior.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.behavior.ApLikesBehaviorControllerApi;
import com.heima.behavior.service.ApLikesBehaviorService;
import com.heima.model.behavior.dto.LikesBehaviorDto;
import com.heima.model.behavior.pojo.ApLikesBehavior;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/likeBehavior")
public class ApLikesBehaviorController implements ApLikesBehaviorControllerApi {

   @Autowired
    ApLikesBehaviorService apLikesBehaviorService;

    /**
     * APP点赞行为表
     * @param dto
     * @return
     */
   @Override
    @PostMapping("/like")
    public ResponseResult like(@RequestBody LikesBehaviorDto dto) {

        return apLikesBehaviorService.like(dto);
    }

    /**
     * 根据文章id和实体id查询
     * @param entryId
     * @param articleId
     * @return
     */
    @GetMapping("/getlike/{entryId}/{articleId}")
    @Override
    public ApLikesBehavior getlike(@PathVariable("entryId") Integer entryId,@PathVariable("articleId") Long articleId) {

       return apLikesBehaviorService.getOne(Wrappers.<ApLikesBehavior>lambdaQuery().eq(ApLikesBehavior::getArticleId,articleId).eq(ApLikesBehavior::getEntryId,entryId));
    }
}
